#include "TidyUpIcon.h"
#include <DesktopIconOrganizer.h>


TidyUpIcon::TidyUpIcon(QWidget* parent) 
	: QMainWindow(parent)
		 
{
	ui.setupUi(this);
    setupUi(); 
    Connection();
	
}
void TidyUpIcon::Connection()
{
	//connect(organizeButton, &QPushButton::clicked, this, &TidyUpIcon::organizeDesktop);
	connect(organizeButton, &QPushButton::clicked, this, &TidyUpIcon::organizeDesktop);

	
}
void TidyUpIcon::checkDesktopStatus() {
	if (!DesktopOrganizer::isDesktopOrganizable()) {
		organizeButton->setEnabled(false);
		QMessageBox::warning(this, "警告", "无法访问桌面目录或没有操作权限！");
	}
}
void TidyUpIcon:: organizeDesktop() 
{

	DesktopIconOrganizer organizer;
	if (organizer.initialize()) {
		// 从坐标(50, 50)开始，以100x80的间距排列图标
		organizer.arrangeIconsToGrid(50, 50, 100, 80);
		organizer.cleanup();
	}


	/*DesktopOrganizer::OrganizeMode mode = static_cast<DesktopOrganizer::OrganizeMode>(
		modeComboBox->currentData().toInt());


	//DesktopOrganizer::arrangeDesktopIcons(0);
	if (DesktopOrganizer::organizeDesktop(mode)) {
		QMessageBox::information(this, "成功", "桌面图标整理完成！");
	}
	else {
		QMessageBox::warning(this, "错误", "桌面图标整理失败！");
	}*/
}


void TidyUpIcon::setupUi()
{
	setWindowTitle("桌面图标整理工具");
	setFixedSize(300, 150);

	QWidget* centralWidget = new QWidget(this);
	setCentralWidget(centralWidget);
	QVBoxLayout* mainLayout = new QVBoxLayout(centralWidget);
	QGridLayout* layout = new QGridLayout();


	modeComboBox = new QComboBox(this);
	//modeComboBox->addItem("按类型整理");
	//modeComboBox->addItem("按修改日期整理");
	//modeComboBox->addItem("按创建日期整理");
	//modeComboBox->addItem("按文件大小整理");
	modeComboBox->addItem("自动排列", DesktopOrganizer::AutoArrange);
	modeComboBox->addItem("对齐网格", DesktopOrganizer::AlignToGrid);
	modeComboBox->addItem("按名称排序", DesktopOrganizer::SortByName);
	modeComboBox->addItem("按日期排序", DesktopOrganizer::SortByDate);
	organizeButton = new QPushButton("整理桌面",this);
	layout->addWidget(modeComboBox);
	layout->addWidget(organizeButton);
	mainLayout->addLayout(layout);

}